package Thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        //生产者
        BlockingQueue<Integer> blockingQueue=new LinkedBlockingQueue<>(1000);
        Thread t1=new Thread(()->{
            int count=0;
            while(true){
                try{               
                    blockingQueue.put(count);
                    System.out.println("生产数据" + count);
                    count++;
                    
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        //消费者
        Thread t2=new Thread(()->{
            while(true){
                try{
                    int n=blockingQueue.take();
                    System.out.println("消费数据"+n);
                    Thread.sleep(500);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
            }
        });    
        t1.start();
        t2.start();    



    }
}
